<?php
session_start();

if(!isset($_SESSION['userid']))//检查 userid 是否已经设置，如果没有设置，提示未登录并跳转首页
{
    echo "<script>alert('您尚未登录！')</script>";
    echo "<script>window.location.href='index.php'</script>";

}

$userid=$_SESSION['userid'];
include ('mysqli_connect.php');

//取数据库中user的所有信息
$sqlb="select * from user_table where user_id={$userid} ;";
$resb=mysqli_query($dbc,$sqlb);
$resultb=mysqli_fetch_array($resb);

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>影视管理系统&emsp;添加新影单</title>
    <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <style>
        body{
            width: 100%;
            overflow: hidden;
            background: url("300046-106.jpg") no-repeat;
            background-size:cover;
            color: black;
        }
    </style>
</head>
<body>
<nav class="navbar navbar-default navbar-static-top" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="#">我的影视库</a>
        </div>
        <div>
            <ul class="nav navbar-nav">
                <li><a href="user_index.php">主页</a></li>
                <li><a href="user_querymovie.php">影视查询</a></li>
                <li class="active"><a href="user_sheet.php">我的收藏</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">个人信息<b class="caret"></b></a>

                    <ul class="dropdown-menu">
                        <li><a href="user_info.php">用户信息</a></li>
                        <li><a href="user_repass.php">修改密码</a></li>
                    </ul>
                </li>
                <li><a href="index.php">退出</a></li>
            </ul>
        </div>
    </div>
</nav>



<h1 style="text-align: center"><strong>添加新影单</strong></h1>
<div style="padding: 10px 500px 10px;">
    <form  action="user_add_newsheet.php" method="POST" style="text-align: center" class="bs-example bs-example-form" role="form">
        <div id="login">
            <div class="input-group"><span  class="input-group-addon">影视单名称</span><input name="sheet_name" type="text" placeholder="请输入新的影单名" class="form-control"></div><br/>
<!--            <div class="input-group"><span  class="input-group-addon">性别</span><input value="--><?php //echo $resultb['user_sex']; ?><!--" name="user_sex" type="text" placeholder="请输入修改后的性别" class="form-control"></div><br/>-->
<!--            <div class="input-group"><span  class="input-group-addon">出生年份</span><input value="--><?php //echo $resultb['user_age']; ?><!--"  name="user_age" type="text" placeholder="请输入修改后的出生年份" class="form-control"></div><br/>-->
            <label><input type="submit" value="确认" class="btn btn-default"></label>
            <label><input type="reset" value="重置当前值" class="btn btn-default"></label>
        </div>
    </form>
</div>



<?php

if ($_SERVER["REQUEST_METHOD"] == "POST")
{

//    shit是该死的新的影视单名称
    $shit = $_POST["sheet_name"];

//    查询当前最大的sheet_id号，然后新的影视单号就是max+1
    $sqlmax="select * from movie_sheet_table where movie_sheet_id = (select max(movie_sheet_id) from movie_sheet_table);";
    $resmax=mysqli_query($dbc,$sqlmax);
    $maxresult=mysqli_fetch_array($resmax);

    $maxid=$maxresult['movie_sheet_id'];
    $maxid=$maxid+1;


    $sqla="insert into movie_sheet_table (movie_sheet_id,user_id,movie_id,sheet_name) 
            values
            ('{$maxid}','{$userid}','0','{$shit}');";
    $resa=mysqli_query($dbc,$sqla);

    if($resa==1)
    {

        echo "<script>alert('添加成功！')</script>";
        echo "<script>window.location.href='user_sheet.php'</script>";

    }
    else
    {
        echo "<script>alert('添加失败！请重新输入！');</script>";

    }

}


?>
</body>
</html>
